From ba3f55e57acd354e4dde9751a5e585c2694b3338 Mon Sep 17 00:00:00 2001 From: "kaf24@firebug.cl.cam.ac.uk" Date: Wed, 30 Nov 2005 17:24:27 +0100 Subject: [PATCH] GNTTABOP_map_grant_ref returns error status and handle as separate fields. Update callers for new interface. Also use int16_t as standard error code type on all public interfaces. Signed-off-by: Keir Fraser --- .../drivers/xen/blkback/blkback.c | 8 +++---- .../drivers/xen/blkback/common.h | 4 ++-- .../drivers/xen/blkback/interface.c | 4 ++-- .../drivers/xen/blktap/blktap.c | 16 +++++++------- .../drivers/xen/blktap/common.h | 2 +- .../drivers/xen/blktap/interface.c | 4 ++-- .../drivers/xen/netback/common.h | 4 ++-- .../drivers/xen/netback/interface.c | 8 +++---- .../drivers/xen/netback/netback.c | 8 +++---- .../drivers/xen/tpmback/common.h | 2 +- .../drivers/xen/tpmback/interface.c | 4 ++-- .../drivers/xen/tpmback/tpmback.c | 8 +++---- tools/libxc/xc_domain.c | 6 ++--- tools/libxc/xc_gnttab.c | 8 ++++--- tools/libxc/xenctrl.h | 14 +++++++----- xen/common/grant_table.c | 17 +++++++------- xen/include/public/dom0_ops.h | 2 +- xen/include/public/grant_table.h | 22 ++++++++++++------- xen/include/public/io/blkif.h | 2 +- 19 files changed, 77 insertions(+), 66 deletions(-) diff --git a/linux-2.6-xen-sparse/drivers/xen/blkback/blkback.c b/linux-2.6-xen-sparse/drivers/xen/blkback/blkback.c index fe478fe336..586ce79d98 100644 --- a/linux-2.6-xen-sparse/drivers/xen/blkback/blkback.c +++ b/linux-2.6-xen-sparse/drivers/xen/blkback/blkback.c @@ -88,10 +88,10 @@ static inline void flush_plugged_queue(void) * handle returned must be used to unmap the frame. This is needed to * drop the ref count on the frame. */ -static u16 pending_grant_handles[MMAP_PAGES]; +static grant_handle_t pending_grant_handles[MMAP_PAGES]; #define pending_handle(_idx, _i) \ (pending_grant_handles[((_idx) * BLKIF_MAX_SEGMENTS_PER_REQUEST) + (_i)]) -#define BLKBACK_INVALID_HANDLE (0xFFFF) +#define BLKBACK_INVALID_HANDLE (~0) #ifdef CONFIG_XEN_BLKDEV_TAP_BE /* @@ -114,7 +114,7 @@ static void fast_flush_area(int idx, int nr_pages) { struct gnttab_unmap_grant_ref unmap[BLKIF_MAX_SEGMENTS_PER_REQUEST]; unsigned int i, invcount = 0; - u16 handle; + grant_handle_t handle; int ret; for (i = 0; i < nr_pages; i++) { @@ -381,7 +381,7 @@ static void dispatch_rw_block_io(blkif_t *blkif, blkif_request_t *req) BUG_ON(ret); for (i = 0; i < nseg; i++) { - if (likely(map[i].handle >= 0)) { + if (likely(map[i].status == 0)) { pending_handle(pending_idx, i) = map[i].handle; #ifdef __ia64__ MMAP_VADDR(pending_idx,i) = gnttab_map_vaddr(map[i]); diff --git a/linux-2.6-xen-sparse/drivers/xen/blkback/common.h b/linux-2.6-xen-sparse/drivers/xen/blkback/common.h index 96eafda2fe..0926ed0731 100644 --- a/linux-2.6-xen-sparse/drivers/xen/blkback/common.h +++ b/linux-2.6-xen-sparse/drivers/xen/blkback/common.h @@ -66,8 +66,8 @@ typedef struct blkif_st { struct work_struct free_work; - u16 shmem_handle; - grant_ref_t shmem_ref; + grant_handle_t shmem_handle; + grant_ref_t shmem_ref; } blkif_t; blkif_t *alloc_blkif(domid_t domid); diff --git a/linux-2.6-xen-sparse/drivers/xen/blkback/interface.c b/linux-2.6-xen-sparse/drivers/xen/blkback/interface.c index 900b482719..15474a3205 100644 --- a/linux-2.6-xen-sparse/drivers/xen/blkback/interface.c +++ b/linux-2.6-xen-sparse/drivers/xen/blkback/interface.c @@ -43,9 +43,9 @@ static int map_frontend_page(blkif_t *blkif, unsigned long shared_page) unlock_vm_area(blkif->blk_ring_area); BUG_ON(ret); - if (op.handle < 0) { + if (op.status) { DPRINTK(" Grant table operation failure !\n"); - return op.handle; + return op.status; } blkif->shmem_ref = shared_page; diff --git a/linux-2.6-xen-sparse/drivers/xen/blktap/blktap.c b/linux-2.6-xen-sparse/drivers/xen/blktap/blktap.c index aa0bdef432..f4c80f22b4 100644 --- a/linux-2.6-xen-sparse/drivers/xen/blktap/blktap.c +++ b/linux-2.6-xen-sparse/drivers/xen/blktap/blktap.c @@ -177,8 +177,8 @@ extern inline domid_t ID_TO_DOM(unsigned long id) */ struct grant_handle_pair { - u16 kernel; - u16 user; + grant_handle_t kernel; + grant_handle_t user; }; static struct grant_handle_pair pending_grant_handles[MMAP_PAGES]; #define pending_handle(_idx, _i) \ @@ -755,17 +755,17 @@ static void dispatch_rw_block_io(blkif_t *blkif, blkif_request_t *req) uvaddr = MMAP_VADDR(user_vstart, pending_idx, i/2); kvaddr = MMAP_VADDR(mmap_vstart, pending_idx, i/2); - if (unlikely(map[i].handle < 0)) { + if (unlikely(map[i].status)) { DPRINTK("Error on kernel grant mapping (%d)\n", - map[i].handle); - ret = map[i].handle; + map[i].status); + ret = map[i].status; cancel = 1; } - if (unlikely(map[i+1].handle < 0)) { + if (unlikely(map[i+1].status)) { DPRINTK("Error on user grant mapping (%d)\n", - map[i+1].handle); - ret = map[i+1].handle; + map[i+1].status); + ret = map[i+1].status; cancel = 1; } diff --git a/linux-2.6-xen-sparse/drivers/xen/blktap/common.h b/linux-2.6-xen-sparse/drivers/xen/blktap/common.h index 38fa80b557..9571b057e1 100644 --- a/linux-2.6-xen-sparse/drivers/xen/blktap/common.h +++ b/linux-2.6-xen-sparse/drivers/xen/blktap/common.h @@ -64,7 +64,7 @@ typedef struct blkif_st { struct work_struct free_work; - u16 shmem_handle; + grant_handle_t shmem_handle; grant_ref_t shmem_ref; } blkif_t; diff --git a/linux-2.6-xen-sparse/drivers/xen/blktap/interface.c b/linux-2.6-xen-sparse/drivers/xen/blktap/interface.c index 8627c1a488..58f30b0cfd 100644 --- a/linux-2.6-xen-sparse/drivers/xen/blktap/interface.c +++ b/linux-2.6-xen-sparse/drivers/xen/blktap/interface.c @@ -43,9 +43,9 @@ static int map_frontend_page(blkif_t *blkif, unsigned long shared_page) unlock_vm_area(blkif->blk_ring_area); BUG_ON(ret); - if (op.handle < 0) { + if (op.status) { DPRINTK(" Grant table operation failure !\n"); - return op.handle; + return op.status; } blkif->shmem_ref = shared_page; diff --git a/linux-2.6-xen-sparse/drivers/xen/netback/common.h b/linux-2.6-xen-sparse/drivers/xen/netback/common.h index 5150cb8844..e1c5bd204f 100644 --- a/linux-2.6-xen-sparse/drivers/xen/netback/common.h +++ b/linux-2.6-xen-sparse/drivers/xen/netback/common.h @@ -45,9 +45,9 @@ typedef struct netif_st { u8 fe_dev_addr[6]; /* Physical parameters of the comms window. */ - u16 tx_shmem_handle; + grant_handle_t tx_shmem_handle; grant_ref_t tx_shmem_ref; - u16 rx_shmem_handle; + grant_handle_t rx_shmem_handle; grant_ref_t rx_shmem_ref; unsigned int evtchn; unsigned int irq; diff --git a/linux-2.6-xen-sparse/drivers/xen/netback/interface.c b/linux-2.6-xen-sparse/drivers/xen/netback/interface.c index 2cd235b222..f4682750cb 100644 --- a/linux-2.6-xen-sparse/drivers/xen/netback/interface.c +++ b/linux-2.6-xen-sparse/drivers/xen/netback/interface.c @@ -127,9 +127,9 @@ static int map_frontend_pages( unlock_vm_area(netif->comms_area); BUG_ON(ret); - if (op.handle < 0) { + if (op.status) { DPRINTK(" Gnttab failure mapping tx_ring_ref!\n"); - return op.handle; + return op.status; } netif->tx_shmem_ref = tx_ring_ref; @@ -145,9 +145,9 @@ static int map_frontend_pages( unlock_vm_area(netif->comms_area); BUG_ON(ret); - if (op.handle < 0) { + if (op.status) { DPRINTK(" Gnttab failure mapping rx_ring_ref!\n"); - return op.handle; + return op.status; } netif->rx_shmem_ref = rx_ring_ref; diff --git a/linux-2.6-xen-sparse/drivers/xen/netback/netback.c b/linux-2.6-xen-sparse/drivers/xen/netback/netback.c index 2941119f6b..0440aa4342 100644 --- a/linux-2.6-xen-sparse/drivers/xen/netback/netback.c +++ b/linux-2.6-xen-sparse/drivers/xen/netback/netback.c @@ -68,7 +68,7 @@ static PEND_RING_IDX dealloc_prod, dealloc_cons; static struct sk_buff_head tx_queue; -static u16 grant_tx_ref[MAX_PENDING_REQS]; +static grant_handle_t grant_tx_handle[MAX_PENDING_REQS]; static gnttab_unmap_grant_ref_t tx_unmap_ops[MAX_PENDING_REQS]; static gnttab_map_grant_ref_t tx_map_ops[MAX_PENDING_REQS]; @@ -412,7 +412,7 @@ inline static void net_tx_action_dealloc(void) pending_idx = dealloc_ring[MASK_PEND_IDX(dc++)]; gop->host_addr = MMAP_VADDR(pending_idx); gop->dev_bus_addr = 0; - gop->handle = grant_tx_ref[pending_idx]; + gop->handle = grant_tx_handle[pending_idx]; gop++; } ret = HYPERVISOR_grant_table_op( @@ -592,7 +592,7 @@ static void net_tx_action(unsigned long unused) sizeof(txreq)); /* Check the remap error code. */ - if (unlikely(mop->handle < 0)) { + if (unlikely(mop->status)) { printk(KERN_ALERT "#### netback grant fails\n"); make_tx_response(netif, txreq.id, NETIF_RSP_ERROR); netif_put(netif); @@ -605,7 +605,7 @@ static void net_tx_action(unsigned long unused) set_phys_to_machine( __pa(MMAP_VADDR(pending_idx)) >> PAGE_SHIFT, FOREIGN_FRAME(mop->dev_bus_addr >> PAGE_SHIFT)); - grant_tx_ref[pending_idx] = mop->handle; + grant_tx_handle[pending_idx] = mop->handle; data_len = (txreq.size > PKT_PROT_LEN) ? PKT_PROT_LEN : txreq.size; diff --git a/linux-2.6-xen-sparse/drivers/xen/tpmback/common.h b/linux-2.6-xen-sparse/drivers/xen/tpmback/common.h index e12d25a1dd..231f28bdb6 100644 --- a/linux-2.6-xen-sparse/drivers/xen/tpmback/common.h +++ b/linux-2.6-xen-sparse/drivers/xen/tpmback/common.h @@ -54,7 +54,7 @@ typedef struct tpmif_st { struct work_struct work; - u16 shmem_handle; + grant_handle_t shmem_handle; grant_ref_t shmem_ref; } tpmif_t; diff --git a/linux-2.6-xen-sparse/drivers/xen/tpmback/interface.c b/linux-2.6-xen-sparse/drivers/xen/tpmback/interface.c index df33db9bfe..c43fd0d72b 100644 --- a/linux-2.6-xen-sparse/drivers/xen/tpmback/interface.c +++ b/linux-2.6-xen-sparse/drivers/xen/tpmback/interface.c @@ -91,9 +91,9 @@ map_frontend_page(tpmif_t *tpmif, unsigned long shared_page) unlock_vm_area(tpmif->tx_area); BUG_ON(ret); - if (op.handle < 0) { + if (op.status) { DPRINTK(" Grant table operation failure !\n"); - return op.handle; + return op.status; } tpmif->shmem_ref = shared_page; diff --git a/linux-2.6-xen-sparse/drivers/xen/tpmback/tpmback.c b/linux-2.6-xen-sparse/drivers/xen/tpmback/tpmback.c index dd14f6087c..8667c8d2fb 100644 --- a/linux-2.6-xen-sparse/drivers/xen/tpmback/tpmback.c +++ b/linux-2.6-xen-sparse/drivers/xen/tpmback/tpmback.c @@ -249,7 +249,7 @@ _packet_write(struct packet *pak, * and send it to the front end. */ tpmif_t *tpmif = pak->tpmif; - u16 handle; + grant_handle_t handle; int rc = 0; unsigned int i = 0; unsigned int offset = 0; @@ -290,7 +290,7 @@ _packet_write(struct packet *pak, handle = map_op.handle; - if (map_op.handle < 0) { + if (map_op.status) { DPRINTK(" Grant table operation failure !\n"); return 0; } @@ -427,7 +427,7 @@ packet_read_shmem(struct packet *pak, u32 i = (last_read / PAGE_SIZE); u32 pg_offset = last_read & (PAGE_SIZE - 1); u32 to_copy; - u16 handle; + grant_handle_t handle; tpmif_tx_request_t *tx; tx = &tpmif->tx->ring[0].req; @@ -455,7 +455,7 @@ packet_read_shmem(struct packet *pak, BUG(); } - if (map_op.handle < 0) { + if (map_op.status) { DPRINTK(" Grant table operation failure !\n"); return -EFAULT; } diff --git a/tools/libxc/xc_domain.c b/tools/libxc/xc_domain.c index 062006094d..8cba15893d 100644 --- a/tools/libxc/xc_domain.c +++ b/tools/libxc/xc_domain.c @@ -365,9 +365,9 @@ int xc_domain_get_vcpu_info(int xc_handle, int xc_domain_ioport_permission(int xc_handle, uint32_t domid, - uint16_t first_port, - uint16_t nr_ports, - uint16_t allow_access) + uint32_t first_port, + uint32_t nr_ports, + uint32_t allow_access) { DECLARE_DOM0_OP; diff --git a/tools/libxc/xc_gnttab.c b/tools/libxc/xc_gnttab.c index 54fb40e6e1..76b7b141c9 100644 --- a/tools/libxc/xc_gnttab.c +++ b/tools/libxc/xc_gnttab.c @@ -42,9 +42,10 @@ do_gnttab_op(int xc_handle, int xc_gnttab_map_grant_ref(int xc_handle, uint64_t host_virt_addr, uint32_t dom, - uint16_t ref, + grant_ref_t ref, uint16_t flags, - int16_t *handle, + int16_t *status, + grant_handle_t *handle, uint64_t *dev_bus_addr) { struct gnttab_map_grant_ref op; @@ -58,6 +59,7 @@ int xc_gnttab_map_grant_ref(int xc_handle, if ( (rc = do_gnttab_op(xc_handle, GNTTABOP_map_grant_ref, &op, 1)) == 0 ) { + *status = op.status; *handle = op.handle; *dev_bus_addr = op.dev_bus_addr; } @@ -69,7 +71,7 @@ int xc_gnttab_map_grant_ref(int xc_handle, int xc_gnttab_unmap_grant_ref(int xc_handle, uint64_t host_virt_addr, uint64_t dev_bus_addr, - uint16_t handle, + grant_handle_t handle, int16_t *status) { struct gnttab_unmap_grant_ref op; diff --git a/tools/libxc/xenctrl.h b/tools/libxc/xenctrl.h index 8afd5b01b2..d12ac4993f 100644 --- a/tools/libxc/xenctrl.h +++ b/tools/libxc/xenctrl.h @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -374,9 +375,9 @@ int xc_domain_memory_decrease_reservation(int xc_handle, int xc_domain_ioport_permission(int xc_handle, uint32_t domid, - uint16_t first_port, - uint16_t nr_ports, - uint16_t allow_access); + uint32_t first_port, + uint32_t nr_ports, + uint32_t allow_access); unsigned long xc_make_page_below_4G(int xc_handle, uint32_t domid, unsigned long mfn); @@ -475,15 +476,16 @@ int xc_grant_interface_close(int xc_handle); int xc_gnttab_map_grant_ref(int xc_handle, uint64_t host_virt_addr, uint32_t dom, - uint16_t ref, + grant_ref_t ref, uint16_t flags, - int16_t *handle, + int16_t *status, + grant_handle_t *handle, uint64_t *dev_bus_addr); int xc_gnttab_unmap_grant_ref(int xc_handle, uint64_t host_virt_addr, uint64_t dev_bus_addr, - uint16_t handle, + grant_handle_t handle, int16_t *status); int xc_gnttab_setup_table(int xc_handle, diff --git a/xen/common/grant_table.c b/xen/common/grant_table.c index 46b16e0daf..5d4955196b 100644 --- a/xen/common/grant_table.c +++ b/xen/common/grant_table.c @@ -114,13 +114,13 @@ __gnttab_map_grant_ref( (GNTMAP_device_map|GNTMAP_host_map)) == 0) ) { DPRINTK("Bad ref (%d) or flags (%x).\n", ref, dev_hst_ro_flags); - (void)__put_user(GNTST_bad_gntref, &uop->handle); + (void)__put_user(GNTST_bad_gntref, &uop->status); return GNTST_bad_gntref; } if ( acm_pre_grant_map_ref(dom) ) { - (void)__put_user(GNTST_permission_denied, &uop->handle); + (void)__put_user(GNTST_permission_denied, &uop->status); return GNTST_permission_denied; } @@ -130,7 +130,7 @@ __gnttab_map_grant_ref( if ( rd != NULL ) put_domain(rd); DPRINTK("Could not find domain %d\n", dom); - (void)__put_user(GNTST_bad_domain, &uop->handle); + (void)__put_user(GNTST_bad_domain, &uop->status); return GNTST_bad_domain; } @@ -145,7 +145,7 @@ __gnttab_map_grant_ref( { put_domain(rd); DPRINTK("Maptrack table is at maximum size.\n"); - (void)__put_user(GNTST_no_device_space, &uop->handle); + (void)__put_user(GNTST_no_device_space, &uop->status); return GNTST_no_device_space; } @@ -155,7 +155,7 @@ __gnttab_map_grant_ref( { put_domain(rd); DPRINTK("No more map handles available.\n"); - (void)__put_user(GNTST_no_device_space, &uop->handle); + (void)__put_user(GNTST_no_device_space, &uop->status); return GNTST_no_device_space; } @@ -370,6 +370,7 @@ __gnttab_map_grant_ref( (void)__put_user((u64)frame << PAGE_SHIFT, &uop->dev_bus_addr); (void)__put_user(handle, &uop->handle); + (void)__put_user(GNTST_okay, &uop->status); put_domain(rd); return rc; @@ -377,7 +378,7 @@ __gnttab_map_grant_ref( unlock_out: spin_unlock(&rd->grant_table->lock); - (void)__put_user(rc, &uop->handle); + (void)__put_user(rc, &uop->status); put_maptrack_handle(ld->grant_table, handle); return rc; } @@ -400,7 +401,7 @@ __gnttab_unmap_grant_ref( { domid_t dom; grant_ref_t ref; - u16 handle; + grant_handle_t handle; struct domain *ld, *rd; active_grant_entry_t *act; grant_entry_t *sha; @@ -957,7 +958,7 @@ gnttab_release_mappings( grant_table_t *gt = d->grant_table; grant_mapping_t *map; grant_ref_t ref; - u16 handle; + grant_handle_t handle; struct domain *rd; active_grant_entry_t *act; grant_entry_t *sha; diff --git a/xen/include/public/dom0_ops.h b/xen/include/public/dom0_ops.h index 4ff18fcd06..5627a441e4 100644 --- a/xen/include/public/dom0_ops.h +++ b/xen/include/public/dom0_ops.h @@ -19,7 +19,7 @@ * This makes sure that old versions of dom0 tools will stop working in a * well-defined way (rather than crashing the machine, for instance). */ -#define DOM0_INTERFACE_VERSION 0xAAAA1013 +#define DOM0_INTERFACE_VERSION 0xAAAA1014 /************************************************************************/ diff --git a/xen/include/public/grant_table.h b/xen/include/public/grant_table.h index c5d0f0bc4f..166e4ae327 100644 --- a/xen/include/public/grant_table.h +++ b/xen/include/public/grant_table.h @@ -133,6 +133,11 @@ typedef struct grant_entry { */ typedef uint32_t grant_ref_t; +/* + * Handle to track a mapping created via a grant reference. + */ +typedef uint32_t grant_handle_t; + /* * GNTTABOP_map_grant_ref: Map the grant entry (,) for access * by devices and/or host CPUs. If successful, is a tracking number @@ -154,11 +159,12 @@ typedef uint32_t grant_ref_t; typedef struct gnttab_map_grant_ref { /* IN parameters. */ uint64_t host_addr; - domid_t dom; - grant_ref_t ref; uint32_t flags; /* GNTMAP_* */ + grant_ref_t ref; + domid_t dom; /* OUT parameters. */ - int32_t handle; /* +ve: handle; -ve: GNTST_* */ + int16_t status; /* GNTST_* */ + grant_handle_t handle; uint64_t dev_bus_addr; } gnttab_map_grant_ref_t; @@ -178,9 +184,9 @@ typedef struct gnttab_unmap_grant_ref { /* IN parameters. */ uint64_t host_addr; uint64_t dev_bus_addr; - uint32_t handle; + grant_handle_t handle; /* OUT parameters. */ - int32_t status; /* GNTST_* */ + int16_t status; /* GNTST_* */ } gnttab_unmap_grant_ref_t; /* @@ -198,7 +204,7 @@ typedef struct gnttab_setup_table { domid_t dom; uint32_t nr_frames; /* OUT parameters. */ - int32_t status; /* GNTST_* */ + int16_t status; /* GNTST_* */ unsigned long *frame_list; } gnttab_setup_table_t; @@ -211,7 +217,7 @@ typedef struct gnttab_dump_table { /* IN parameters. */ domid_t dom; /* OUT parameters. */ - int32_t status; /* GNTST_* */ + int16_t status; /* GNTST_* */ } gnttab_dump_table_t; /* @@ -229,7 +235,7 @@ typedef struct { domid_t domid; grant_ref_t ref; /* OUT parameters. */ - int32_t status; + int16_t status; } gnttab_transfer_t; /* diff --git a/xen/include/public/io/blkif.h b/xen/include/public/io/blkif.h index 3a9bf2e7bb..9a91ef82f9 100644 --- a/xen/include/public/io/blkif.h +++ b/xen/include/public/io/blkif.h @@ -43,7 +43,7 @@ typedef struct blkif_request { typedef struct blkif_response { uint64_t id; /* copied from request */ uint8_t operation; /* copied from request */ - int32_t status; /* BLKIF_RSP_??? */ + int16_t status; /* BLKIF_RSP_??? */ } blkif_response_t; #define BLKIF_RSP_ERROR -1 /* non-specific 'error' */ -- 2.30.2